import type { Module } from 'vuex'
import type { SysDict, RootStateTypes } from '../interface'
import type { default as SysDictEntity } from '@jsjn/types/entity/SysDict'
import { assignOwnProp } from '@jsjn/utils'
import { forParent } from '@jsjn/micro-core-micro-main/sendData'

const loginInfo: Module<SysDict, RootStateTypes> = {
    namespaced: true,
    state() {
        return {
            list: []
        }
    },
    mutations: {
        setSysDictList(state, sysDictLisst: SysDictEntity[]) {
            state.list = sysDictLisst
        },
        // 全量赋值
        setSysDictStoreModule(state, data: SysDict) {
            const currentState = JSON.stringify(state)
            const nextState = JSON.stringify(data)
            if (currentState === nextState) return
            assignOwnProp(state, data)
        }
    },
    actions: {
        /**
         * uums 业务系统需要在改变字典表后
         * 通知基座应用，更新存储的字典表
         */
        updateSysDictList() {
            forParent({ updateSysDictList: +new Date() })
        }
    }
}

export default loginInfo
